<?php
/*
 * @Author: 孙开源 && sunkaiyuan@namenode.cn
 * @Date: 2023-04-12 16:45:39
 * @LastEditors: 孙开源 && sunkaiyuan@namenode.cn
 * @LastEditTime: 2023-04-23 15:48:00
 * @Description: 
 * 
 */
namespace szzhijing;

use szzhijing\Kernel\Support\Collection;
use Pimple\Container;

/** 
 * @property \szzhijing\ColorDe\Client $ColorDe 
 * @property \szzhijing\OIDC\Client $OIDC 
 * @property Collection $config 
 * 
 * @property \szzhijing\Kernel\Client $client
 * @property \szzhijing\Kernel\Services\AccessToken $access_token
 * @property \szzhijing\Kernel\Services\Cacher $cacher
 * @property \szzhijing\Kernel\Services\Logger $logger
 * @property \szzhijing\Kernel\Services\Interceptor $interceptor
 */
class Application extends Container
    {
    //默认值
    protected $_defaultconfig = [
        'clientId'     => "",
        'orgCode'      => "",
        'clientSecret' => "",
        'orgName'      => "",
        'log'          => [
            'enable' => false
        ],
    ];
    /**
     * @var array
     */
    protected $providers = [

        OIDC\ServiceProvider::class,
        ColorDe\ServiceProvider::class,

        Kernel\Providers\LoggerServiceProvider::class,
        Kernel\Providers\RequestServiceProvider::class,
        Kernel\Providers\AccessTokenServiceProvider::class,
        Kernel\Providers\InterceptorServiceProvider::class,
        Kernel\Providers\CacherServiceProvider::class,
    ];


    /**
     * Application constructor.
     *
     * @param array $config
     * @param array $values
     */
    public function __construct($config = [], array $values = [])
        {
        parent::__construct($values);

        $this['config'] = function () use ($config)
            {
            return new Collection(array_merge($this->_defaultconfig, $config));
            };

        foreach ($this->providers as $provider) {
            $this->register(new $provider());
            }
        }

    public static function make($name, $config)
        {
        return (new self($config))->$name;
        }
    public static function __callStatic($name, $arguments)
        {
        return self::make($name, ...$arguments);
        }
    /**
     * @param $name
     *
     * @return mixed
     */
    public function __get($name)
        {
        return $this[$name];
        }
    }